/********************************************************************
 * PROJECT: CSAIR ROST PROJECT.
 * SUPPLIER: FOREVER OPEN SOURCE SOFTWARE INC.
 ********************************************************************
 * FILE: GanttColumnMenu.java
 * (C) Copyright Foliage Team 2013, All Rights Reserved.
 ********************************************************************/
package org.foliage.rcp.ui.custom;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class GanttColumnMenu extends Shell {

	// ----------------------------------------------- 

	private final GanttGridColumn column;

	private GanttGridFilter filter;

	// ----------------------------------------------- 

	public GanttColumnMenu(GanttGridColumn column) {
		super(Display.getDefault(), SWT.ON_TOP | SWT.TOOL | SWT.NO_TRIM | SWT.NO_FOCUS);
		this.column = column;
		init();
		initListeners();
	}

	// ----------------------------------------------- 

	@Override
	protected void checkSubclass() {}

	// ----------------------------------------------- 

	private void init() {
		setLayout(new FillLayout());
		filter = new GanttGridFilter(this, column);
		Point location = new Point(column.getBounds().x, column.getBounds().y + column.getHeaderHeight() + 2);
		location = Display.getDefault().map(column.getParent(), null, location);
		setLocation(location);
		pack();
		setActive();
	}

	private void initListeners() {
		addShellListener(new ShellAdapter() {

			@Override
			public void shellDeactivated(ShellEvent e) {
				dispose();
			}

		});
	}

	// ----------------------------------------------- 

	public void setItems(GanttGridItem[] items) {
		filter.setItems(items);
	}

}
